package com.tms.dep.controller;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;


import com.tms.dep.domain.TmsDep;
import com.tms.dep.service.ITmsDepService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 部门管理Controller
 * 
 * @author ruoyi
 * @date 2024-10-30
 */
@RestController
@RequestMapping("/dep")
public class TmsDepController extends BaseController
{
    @Autowired
    private ITmsDepService tmsDepService;

    /**
     * 查询部门管理列表
     */
    @RequiresPermissions("dep:dep:list")
    @GetMapping("/list")
    public TableDataInfo list(TmsDep tmsDep)
    {
        startPage();
        List<TmsDep> list = tmsDepService.selectTmsDepList(tmsDep);
        return getDataTable(list);
    }

    /**
     * 导出部门管理列表
     */
    @RequiresPermissions("dep:dep:export")
//    @Log(title = "部门管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TmsDep tmsDep)
    {
        List<TmsDep> list = tmsDepService.selectTmsDepList(tmsDep);
        ExcelUtil<TmsDep> util = new ExcelUtil<TmsDep>(TmsDep.class);
        util.exportExcel(response, list, "部门管理数据");
    }

    /**
     * 获取部门管理详细信息
     */
    @RequiresPermissions("dep:dep:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tmsDepService.selectTmsDepById(id));
    }

    /**
     * 新增部门管理
     */
    @RequiresPermissions("dep:dep:add")
//    @Log(title = "部门管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TmsDep tmsDep)
    {
        tmsDep.setCreatedAt(new Date());
        return toAjax(tmsDepService.insertTmsDep(tmsDep));
    }

    /**
     * 修改部门管理
     */
    @RequiresPermissions("dep:dep:edit")
//    @Log(title = "部门管理", businessType = BusinessType.UPDATE)/
    @PutMapping
    public AjaxResult edit(@RequestBody TmsDep tmsDep)
    {
        return toAjax(tmsDepService.updateTmsDep(tmsDep));
    }

    /**
     * 删除部门管理
     */
    @RequiresPermissions("dep:dep:remove")
//    @Log(title = "部门管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tmsDepService.deleteTmsDepByIds(ids));
    }
}
